import * as React from 'react';
import * as monaco from 'monaco-editor-core';

export interface EditorInterface extends monaco.editor.IStandaloneEditorConstructionOptions {
    style?: any
}
const Editor: React.FC<EditorInterface> = (props: EditorInterface) => {
    console.assert(props.language?.length, '请设置language')
    let divNode;
    const assignRef = React.useCallback((node) => {
        // On mount get the ref of the div and assign it the divNode
        divNode = node;
    }, []);

    React.useEffect(() => {
        if (divNode) {
            const editor = monaco.editor.create(divNode, {
                // language: language,
                minimap: { enabled: false },
                autoIndent: 'advanced',
                ...props
            });
        }
    }, [assignRef])
    return <div ref={assignRef} style={props.style ?? { height: '90vh' }}></div>;
}

export { Editor };